package com.sjgtw.cloud.system.api.fallbackfactory;

import com.sjgtw.cloud.common.core.domain.R;
import com.sjgtw.cloud.system.api.model.LoginUser;
import com.sjgtw.cloud.system.api.service.RemoteUserService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * <p>Title: 用户服务异常处理</p>
 * <p>Description: </p>
 * @author Admin
 * @date 2021-4-7
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginUser> getUser(Long userId) {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
			public R<Integer> lockUserStatus(Long userid) {
				return null;
			}
        };
    }
}
